package com.lms.lambda;

import java.util.function.Function;

/**
 * @Author: 李孟帅
 * @CreateTime: 2020-05-12 07:14
 * @Description: ${Description}
 */

public class FunctionDemo {
    public static void main(String[] args) {
//        Function<Integer, Integer> fun= i-> i*2;

        Function<Integer, Integer> fun = i -> i * 2;
        Function<Integer, Integer> andThen = fun.andThen(n -> n + 1);  // (i*2)+1
        System.out.println(andThen.apply(2));
        Integer apply1 = fun.compose(n -> (Integer)n+3 ).apply(6);  // (6+3)*2
        System.out.println(apply1);
        Function<Integer, Integer> identity = Function.identity();
//        static <T> Function<T, T> identity() {
//            return t -> t;
//        }
        System.out.println(identity.apply(apply1));
    }
}
